package com.ruoyi.framework.config;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * mybatis-plus自动填充策略设置
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    //进行插入时填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createBy",SecurityUtils.getUsername(), metaObject);
        this.setFieldValByName("createTime", new Date(), metaObject);
    }

    //进行修改操作时填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
        this.setFieldValByName("updateBy", SecurityUtils.getUsername(), metaObject);
    }
}

